function [u, s, t] = hwk2(A1, A2, A3)
% Arguments:
% A1 - Amplitude of first cosine wave
% A2 - Amplitude of second cosine wave
% A3 - Amplitude of third cosine wave
% Outputs:
% u - Sum of three cosine waves
%
% Paul Ozog
% Communications
% Hw 2 - Suppressed carrier AM

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Part I - plot u(t) and s(t)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Declare constants and time vectors
fc = 10e3;
Fs = 4*fc;
t = 0:1/Fs:.01;

% Assign vectors for time domain
u = A1*cos(2*pi*200*t) + A2*cos(2*pi*2000*t) + A3*cos(2*pi*1000*t); 
carrier = cos(2*pi*fc*t);
s = u .* carrier;

% Plot
subplot(2,2,1);
plot(t,u);
title(['u(t), A1 = ', num2str(A1),', A2 = ', num2str(A2),', A3 = ', num2str(A3)]);
xlabel('Time (seconds)')
ylabel('u(t)')
subplot(2,2,2);
plot(t,s);
title('s(t)')
xlabel('Time (seconds)')
ylabel('s(t)')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Part II - plot U(f) and S(f)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Declare constants and time vectors
L = length(t);

% Assign vectors for frequency domain
U = fft(u)/L;
S = fft(s)/L;
U_centered = fftshift(U);
S_centered = fftshift(S);

% Create a frequency vector that ranges from -Fs/2 to Fs/2
f = linspace(-Fs/2, Fs/2, L);

% Plot double-sided amplitude spectrum.
subplot(2,2,3);
plot(f,abs(U_centered));
title('Double-Sided Amplitude Spectrum of u(t)')
xlabel('Frequency (Hz)')
ylabel('|U(f)|')
axis([-2500 2500 0 0.5])

% Plot double-sided amplitude of S
subplot(2,2,4);
plot(f,abs(S_centered));
title('Double-Sided Amplitude Spectrum of s(t)')
xlabel('Frequency (Hz)')
ylabel('|S(f)|')
axis([-15e3 15e3 0 0.25])
